# 
#     Class CarraraObject : keep implementation link to Carrara
# 

import c3d
from PyCarrara import *
import PyCarrara

class CarraraObject(object):
  def __init__(self,obj=None,name=None,position=Vector(0.0,0.0,0.0),scene=None,orientation=Vector(0.0,0.0,0.0),mode="G" ):
    super(CarraraObject,self).__init__()
    if obj is not None:
      self.object=obj
      self.name = obj.get_fullname()
    else:
      self.name = name
      self.object =  c3d.Object ("/" + name)
    self.position = position
    self.orientation = orientation
    self.scene = scene
    self.mode = mode
#     self.init()
    
  def move(self):
    t = c3d.get_time()
    self.object.set_keyframe(t,"/Instance/Motion Method/Transform/Rotation",self.orientation)
    self.object.set_keyframe_translation(t,self.position)   
    
  def refresh(self):      
    self.orientation = self.object.get_rotation(self.mode)
    self.position = self.object.get_translation(self.mode)
    
  def init(self):
    self.object.clear_keyframes('*')
    
  